package com.hu.zhcc.shiro.controller;

import com.github.pagehelper.PageInfo;
import com.hu.zhcc.shiro.entity.bo.CheckItem;
import com.hu.zhcc.shiro.entity.dto.RoleDTO;
import com.hu.zhcc.shiro.entity.vo.CheckItemVO;
import com.hu.zhcc.shiro.entity.vo.RoleDetailVO;
import com.hu.zhcc.shiro.entity.vo.RoleListVO;
import com.hu.zhcc.shiro.service.CheckItemService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 检查项管理
 */

@RestController
@RequestMapping("/checkitem")
public class CheckItemController{
    @Autowired
    private CheckItemService checkItemService;

    @GetMapping("")
    public PageInfo<CheckItem> homecheckItem(CheckItemVO checkItemVO){
        PageInfo<CheckItem> checkItemPageInfo = checkItemService.selectByCondition(checkItemVO);
        return checkItemPageInfo;
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<?> removeDept(@PathVariable("id") int id) {
        return checkItemService.deleteByPrimaryKey(id) > 0 ? ResponseEntity.noContent().build() :
                ResponseEntity.notFound().build();
    }

    @GetMapping("/{id}")
    public List<CheckItem> getById(@PathVariable("id") int id) {
        return checkItemService.selectByCheckGroupId(id);
    }

    @PostMapping("")
    public ResponseEntity<?> saveCheckitem(@RequestBody CheckItem checkItem) {
        return checkItemService.insert(checkItem) > 0 ? ResponseEntity.noContent().build() :
                ResponseEntity.notFound().build();
    }

    @PutMapping("/{id}")
    public ResponseEntity<Integer> updateCheckitem(@PathVariable("id") int id, @RequestBody CheckItem checkItem) {
        int i = checkItemService.updateByPrimaryKeySelective(checkItem);
        return i == 0 ? ResponseEntity.notFound().build() :
                ResponseEntity.status(HttpStatus.CREATED).body(i);
    }

    @GetMapping("/all")
    public List<CheckItem> listAllCheckItem() {
        return checkItemService.findAll();
    }
}
